<?php
if (!$_GET['id']) {
    echo "Bad Request";
} else {
    $id = $_GET['id'];
//including header.php 
    include '../../include/header.php';
//including page.php (It is a class which contain functions)
    include '../../libraries/page.php';
    $page = new page();
    session_start();
    $userid = $_SESSION['userid'];

//checking the session
    if (!$_SESSION['username']) {
        header("location:../user/login.php");
    }
    if ($_GET['q'] == 'logout') {
        $page->user_logout();
        header("location:../user/login.php");
    }

    if ($_SERVER["REQUEST_METHOD"] == "POST") {
// for $_POST['submit'].  Remember, field names are determined by array keys!
        $result = $page->add_combination("combinations", $id, $_POST['c_product_id']);
        if ($result) {
            $msg = $message[1];
        } else {
            $msg = $message[0];
        }
    }
    $products = 'active';
    include '../../include/navbar.php';
    ?>

<div class="bread_crumb" style="margin-left: 2%">
    &laquo;  <a href="products">Back</a>
  </div>

    <!----------------------------------Display the result message of Update--------------------->
    <div  align="center"><? echo $msg; ?></div>

    <!-------------------------------------------form----------------------------------------------->
    <form action="" method="post">


        <!-------------------------------------main div------------------------------------->
        <div style="width: 285px;margin-left: auto;margin-right: auto; margin-top: 50px;">
            <h3 style="color:#777;text-align: center"> Add Combination</h3>
            <br />
            <label>Group</label>
            <select name="c_product_id" style="width:285px">
                <!-----------------We are retrieving data from database table to display in the fields to update--------->
                <?
                //php code to get the data from products table 
                $products = mysql_query("select * from products where productid <> $id");
                while ($products_data = mysql_fetch_array($products)) {

                $product_id = $products_data['productid'];
                $name = ucwords(strtolower($products_data['name']));
                $code = $products_data['code'];
                ?>
                <option value="<?= $product_id; ?>"><?= $name; ?></option>
                <?
                }
                ?>
            </select>
            <button class="btn btn-inverse" type="submit"   style="float:right; margin-top: 20px;">Add</button> 
    </form>
    </div>
    <?php
//including footer.php
    include '../../include/footer.php';
    ?>
    <?php
}
?>